/*
 This file 'top.$.dialog' is part of Firebird Integrated Solution 1.0

 Copyright (c) 2015 Lincong

 Contact:  
 Email: lincong1987@gmail.com

 QQ: 159257119

 See Usage at http://www.jplatformx.com/firebird

 Create date: 2015-03-16 01:40
 */

define(function (require, exports, module) {

	require("dialog");
	require("Firebird.ui.Component");


	/**
	 * 确认提示
	 * @param content
	 * @param ok
	 * @param cancel
	 * @param options
	 * @returns {*}
	 */

	/**
	 * tips
	 * @param content
	 * @param time
	 * @param options
	 * @returns {*}
	 */

	/**
	 * 打开
	 * @param url
	 * @param options
	 * @returns {*}
	 */

	/**
	 * 提醒
	 * @param content
	 * @param ok
	 * @param options
	 * @returns {*}
	 */

	/**
	 * 警告
	 * @param content
	 * @param ok
	 * @param cancel
	 * @param options
	 * @returns {*}
	 */

	/**
	 * 错误
	 * @param content
	 * @param ok
	 * @param options
	 * @returns {*}
	 */

	/**
	 *   Firebird.ui.Dialog
	 */
	Firebird.define("Firebird.ui.Dialog", {

		extend: "Firebird.ui.Component",

		statics: {

			notice: function (content, options) {
				options = $.extend({}, {
						title: "提醒",
						content: "" +
							"	<table class='fb-ui-dialog-table fb-ui-dialog-alert-table'>" +
							"	<tr>" +
							"		<td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td>" +
							"		<td class='fb-ui-dialog-table-content'><br>" + content + "</td>" +
							"	</tr>" +
							"	</table>",
						padding: "10px",
						width: 400,
						lock: true,
						fixed: true,
						quickClose: false,
						skin: 'fb-ui-dialog fb-ui-notice'
					},
					options || {});

				var dia = _top.$.dialog(options);

				window.__popup = dia.__popup;
				var topHeight = _top.$(_top).height();
				var topWidth = _top.$(_top).width();

				dia.show(null, {
					left: topWidth - dia.__popup.width() - 10,
					top: topHeight
				});

				dia.__popup.animate({top: topHeight - dia.__popup.height() - 10}, 800);

				return dia;
			},

			confirm: function (content, ok, cancel, options) {
				options = $.extend({}, {
						title: "请确认以下操作",
						content: "<table class='fb-ui-dialog-table fb-ui-dialog-confirm-table'><tr><td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td><td class='fb-ui-dialog-table-content'><br>" + content + "</td></tr></table>",
						width: 400,
						lock: true,
						quickClose: false,
						padding: "10px",
						okValue: '确 定',
						cancelValue: "取 消",
						ok: ok || $.noop,
						cancel: cancel || $.noop,
						skin: 'fb-ui-dialog fb-ui-confirm'
					},
					options || {});
				return _top.$.dialog(options)[options && options.lock === true ? "showModal" : "show"]((options && options.follow) || null);
			},

			error: function (content, ok, options) {
				var $content = $("<table class='fb-ui-dialog-table fb-ui-dialog-error-table'><tr><td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td><td class='fb-ui-dialog-table-content'><br></td></tr></table>")
				if (typeof (content) == "object" || typeof (content) == "string") {
					$content.find(".fb-ui-dialog-table-content").append(content);
				}
				options = $.extend({}, {
						title: "错误",
						width: 400,
						lock: true,
						quickClose: false,
						content: $content,
						padding: "10px",
						okValue: '确 定',
						ok: ok || $.noop,
						skin: 'fb-ui-dialog fb-ui-error'
					},
					options || {});
				return _top.$.dialog(options)[options && options.lock === true ? "showModal" : "show"]((options && options.follow) || null);
			},

			warn: function (content, ok, cancel, options) {
				options = $.extend({}, {
						title: "警告",
						content: "<table class='fb-ui-dialog-table fb-ui-dialog-warn-table'><tr><td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td><td class='fb-ui-dialog-table-content'><br>" + content + "</td></tr></table>",
						width: 400,
						lock: true,
						quickClose: false,
						okValue: '确 定',
						ok: ok || $.noop,
						skin: 'fb-ui-dialog fb-ui-warn'
					},
					options || {});
				return _top.$.dialog(options)[options && options.lock === true ? "showModal" : "show"]((options && options.follow) || null);
			},

			alert: function (content, ok, options) {
				options = $.extend({}, {
						title: "提醒",
						content: "<table class='fb-ui-dialog-table fb-ui-dialog-alert-table'><tr><td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td><td class='fb-ui-dialog-table-content'><br>" + content + "</td></tr></table>",
						padding: "10px",
						width: 400,
						lock: true,
						quickClose: false,
						okValue: '确 定',
						ok: ok || $.noop,
						skin: 'fb-ui-dialog fb-ui-alert'
					},
					options || {});
				return _top.$.dialog(options)[options && options.lock === true ? "showModal" : "show"]((options && options.follow) || null);
			},

			success: function (content, ok, options) {
				options = $.extend({}, {
						title: "操作成功",
						content: "<table class='fb-ui-dialog-table fb-ui-dialog-success-table'><tr><td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td><td class='fb-ui-dialog-table-content'><br>" + content + "</td></tr></table>",
						padding: "10px",
						width: 400,
						lock: true,
						quickClose: false,
						okValue: '确 定',
						ok: ok || $.noop,
						skin: 'fb-ui-dialog fb-ui-success'
					},
					options || {});
				var dia = _top.$.dialog(options)[options && options.lock === true ? "showModal" : "show"]((options && options.follow) || null);
				if (typeof options.time != "undefined") {
					setTimeout(function () {
						dia.close().remove();
						dia = null;
					}, options.time);
				}
				return dia;
			},

			/**
			 * tips
			 * @param content
			 * @param time
			 * @param options
			 * @returns {*}
			 */
			tips: function (content, time, options) {
				options = $.extend({}, {
						width: 300,
						padding: "10px",
						quickClose: false,
						content: content || "请稍等...",
						skin: 'fb-ui-dialog fb-ui-tips'
					},
					options || {});
				var dia = _top.$.dialog(options)[options && options.lock === true ? "showModal" : "show"]((options && options.follow) || null);

				setTimeout(function () {
					dia.close().remove();
					dia = null;
				}, time || 2000);

				return dia;
			},

			wait: function (content, time, options) {

				options = $.extend(true, {}, {
						width: 300,
						padding: "10px",
						quickClose: false,
						content: content || "请稍等...",
						skin: 'fb-ui-dialog fb-ui-tips fb-ui-wait'
					},
					options || {});

				return this.tips.apply(this, [
					"<table class='fb-ui-dialog-table fb-ui-dialog-warn-table'><tr><td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td><td class='fb-ui-dialog-table-content'><br>" + content + "</td></tr></table>", time, options
				]);
			},

			done: function (content, time, options) {
				return this.tips.apply(this, [
					"<table class='fb-ui-dialog-table fb-ui-dialog-warn-table'><tr><td width='100' class='fb-ui-dialog-table-icon'>&nbsp;</td><td class='fb-ui-dialog-table-content'><br>" + content + "</td></tr></table>", time, options
				]);
			},

			open: function (url, options) {
				options = $.extend({}, {
						title: "业务操作",
						url: url,
						lock: true,
						quickClose: false,
						_wait_dialog: null,
						skin: 'fb-ui-dialog fb-ui-open'
					},
					options || {});

				options._wait_dialog = _top.$.dialog.wait("请稍等，资源正在加载...", 10000, {
					id: "_wait_dialog",
					lock: true,
					// 设置遮罩背景颜色
					backdropBackground: '#fff',
					// 设置遮罩透明度
					backdropOpacity: 0
				});

				return _top.$.dialog(options);//[options && options.lock === true ? "showModal" : "show"]((options && options.follow) || null);
			}
		}
	});
	                                       
	module.exports = Firebird.ui.Dialog;
});